package cn.cs.message;

import java.io.UnsupportedEncodingException;

import com.alibaba.fastjson.JSONObject;

import cn.cs.message.support.DefaultReminder;
import cn.cs.message.support.MessageNameService;
import cn.cs.message.support.Reminder;

public class MessageClient 
{
	/**链接消息队列的URI： amqp://user:pass@host:port/vhost */
	protected String connectUri;
	
	/**应用系统编码*/
	protected String appCode;
	
	protected Reminder reminder=new DefaultReminder();
	protected MessageNameService messageNameService;
	protected boolean direction;
	
	protected ConnectionManage connectManage;
	protected ReconnectHandler reconnectHandler;
	
	/**序列化Message,转成json串再getbyte*/
	public static byte[] getBytes(Message message)
	{
		String jsonStr=JSONObject.toJSONString(message);
		try {
			return jsonStr.getBytes("UTF-8");
		} catch (UnsupportedEncodingException e) {
			return jsonStr.getBytes();
		}
	}
	
	/**序列化Message,转成json串再getbyte*/
	public static Message getFromBytes(byte[] bytes)
	{
		String jsonStr;
		try {
			jsonStr=new String(bytes,"UTF-8");
		} catch (UnsupportedEncodingException e) {
			jsonStr=new String(bytes);
		}
		
		return JSONObject.parseObject(jsonStr, Message.class);
	}
	
	public String getAppCode() {
		return appCode;
	}

	public void setAppCode(String appCode) {
		this.appCode = appCode;
	}

	public String getConnectUri() {
		return connectUri;
	}

	public void setConnectUri(String connectUri) {
		this.connectUri = connectUri;
	}

	public Reminder getReminder() {
		return reminder;
	}

	public void setReminder(Reminder reminder) {
		this.reminder = reminder;
	}

	public boolean isDirection() {
		return direction;
	}

	public void setDirection(boolean direction) {
		this.direction = direction;
	}
	
}
